<template>
    <div class="qingwu">
        <div class="admin_table_page_title"><a-button @click="$router.back()" class="float_right" icon="arrow-left">返回</a-button>投诉列表</div>
        <div class="unline underm"></div>

        <estate-search :searchConfig="searchConfig" @searchParams="search"></estate-search>

        <div class="admin_table_handle_btn">
            <!-- <a-button @click="$router.push('/Estate/orders/form')" type="primary" icon="plus">添加</a-button>
            <a-button class="admin_delete_btn" type="danger" icon="delete" @click="del">批量删除</a-button> -->
        </div>
        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :loading="table_loading" :pagination="false" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" row-key="id">

                <span slot="nickname" slot-scope="rows">
                    <p>ID:  {{ rows.user.id }}</p>
                    <p>昵称：{{ rows.user.nickname }}</p>
                </span>
                <span slot="status" slot-scope="rows">
                    <a-tag color="red" v-if="rows.status==0">待处理</a-tag>
                    <a-tag color="blue" v-if="rows.status==1">处理中</a-tag>
                    <a-tag color="green" v-if="rows.status==2">已完成</a-tag>
                </span>
                <span slot="action" slot-scope="rows">
                    <a-button icon="read" @click="$router.push('/Estate/complain/detail/'+rows.id)">查看详情</a-button>
                </span>
            </a-table>
            <div class="admin_pagination" v-if="total>0">
                <a-pagination v-model="params.page" :page-size.sync="params.per_page" :total="total" @change="onChange" show-less-items />
            </div>
        </div>
    </div>
</template>

<script>
import estateSearch from '@/components/estate/search'
export default {
    components: {estateSearch},
    props: {},
    data() {
      return {
          params:{
              page:1,
              per_page:30,
          },
          total:0, //总页数
          searchConfig:[
              {label: '所属小区', name: 'c_id', type: 'select', data: [{label: '全部', value: ''}]},
              {label:'投诉时间',name:'created_at',type:'date_picker'},
              {label:'状态',name:'status',type:'select',data:[
                  {label:'全部',value:''},
                  {label:'待处理',value:0},
                  {label:'未处理',value:1},
                  {label:'已完成',value:2},
              ]},
              {label:'用户ID',name:'user_id',type:'text'},
          ],
          selectedRowKeys:[], // 被选择的行
          columns:[
            //   {title:'#',dataIndex:'id',fixed:'left'},
              {title:'小区',dataIndex:'community.community_name'},
              {title:'业主',scopedSlots: { customRender: 'nickname' }},
              {title:'投诉内容',dataIndex:'content_text'},
              {title:'处理状态',key:'id',scopedSlots: { customRender: 'status' }},
              {title:'投诉时间',dataIndex:'created_at'},
              {title:'操作',key:'id',fixed:'right',scopedSlots: { customRender: 'action' }},
          ],
          list:[],
          table_loading: true,
      };
    },
    watch: {},
    computed: {},
    methods: {
        search(params){
            let page = this.params.page;
            let per_page = this.params.per_page;

            // 事件需要格式化，后面再看看有没有更好得到办法
            if(!this.$isEmpty(params.created_at) && !this.$isEmpty(params.created_at[0])){
                params.created_at[0] = moment(params.created_at[0]).format('YYYY-MM-DD HH:mm:ss');
                params.created_at[1] = moment(params.created_at[1]).format('YYYY-MM-DD HH:mm:ss');
            }
            this.params = params;
            this.params.page = page;
            this.params.per_page = per_page;
            this.onload();
        },
        // 选择框被点击
        onSelectChange(selectedRowKeys) {
            this.selectedRowKeys = selectedRowKeys;
        },
        // 选择分页
        onChange(e){
            this.params.page = e;
        },
        // 删除
        del(){
            if(this.selectedRowKeys.length==0){
                return this.$message.error('未选择数据.');
            }
            this.$confirm({
                title: '你确定要删除选择的数据？',
                content: '确定删除后无法恢复.',
                okText: '是',
                okType: 'danger',
                cancelText: '取消',
                onOk:()=> {
                    let ids = this.selectedRowKeys.join(',');
                    this.$delete(this.$api.estateOrders+'/'+ids).then(res=>{
                        if(res.code == 200){
                            this.onload();
                            this.$message.success('删除成功');
                        }else{
                            this.$message.error(res.msg)
                        }
                    });

                },
            });
        },
        get_group() {
            this.$get(this.$api.estateCommunity, {limit: 999}).then(res => {
                let list = [];
                res.data.data.forEach(item => {
                    list.push({label: item.community_name, value: item.community_id})
                })
                this.searchConfig.forEach(item => {
                    if (item.name == 'c_id') {
                        item.data = item.data.concat(list)
                    }
                })
            });
        },
        onload(){
            // if(!this.$isEmpty(this.$route.query.is_refund)){
            //     this.params.is_refund = 1;
            // }
            // if(!this.$isEmpty(this.$route.query.is_return)){
            //     this.params.is_return = 1;
            // }
            this.table_loading = true;
            this.$get(this.$api.estateComplain,this.params).then(res=>{
                this.total = res.data.total;
                this.list = res.data.data;
                this.table_loading = false;
            });
        },
    },
    created() {
        this.onload();
        this.get_group();
    },
    mounted() {}
};
</script>
<style lang="scss" scoped>

</style>
